import { defineStore } from 'pinia';

import { type PositionType } from '@/hooks/usePosition';
import { reactive } from 'vue';
import { MapTile, type MapType } from '@/constants';

export const useMapStore = defineStore('map', () => {
  const map = reactive<MapType>([]);

  const setupMap = (newMap: MapType) => {
    map.splice(0, map.length, ...newMap);
  };

  function isWall({ x, y }: PositionType) {
    return map[y][x] === MapTile.WALL;
  }

  return { map, setupMap, isWall };
});
